\(\int (a+b \tan ^2(e+f x))^2 \, dx\) [207]

   Optimal result
   Rubi [A] (verified)
   Mathematica [A] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [A] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [B] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 14, antiderivative size = 46 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=(a-b)^2 x+\frac {(2 a-b) b \tan (e+f x)}{f}+\frac {b^2 \tan ^3(e+f x)}{3 f} \]

[Out]

(a-b)^2*x+(2*a-b)*b*tan(f*x+e)/f+1/3*b^2*tan(f*x+e)^3/f

Rubi [A] (verified)

Time = 0.03 (sec) , antiderivative size = 46, normalized size of antiderivative = 1.00, number of steps used = 4, number of rules used = 3, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.214, Rules used = {3742, 398, 209} \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=\frac {b (2 a-b) \tan (e+f x)}{f}+x (a-b)^2+\frac {b^2 \tan ^3(e+f x)}{3 f} \]

[In]

Int[(a + b*Tan[e + f*x]^2)^2,x]

[Out]

(a - b)^2*x + ((2*a - b)*b*Tan[e + f*x])/f + (b^2*Tan[e + f*x]^3)/(3*f)

Rule 209

Int[((a_) + (b_.)*(x_)^2)^(-1), x_Symbol] :> Simp[(1/(Rt[a, 2]*Rt[b, 2]))*ArcTan[Rt[b, 2]*(x/Rt[a, 2])], x] /;
 FreeQ[{a, b}, x] && PosQ[a/b] && (GtQ[a, 0] || GtQ[b, 0])

Rule 398

Int[((a_) + (b_.)*(x_)^(n_))^(p_)*((c_) + (d_.)*(x_)^(n_))^(q_), x_Symbol] :> Int[PolynomialDivide[(a + b*x^n)
^p, (c + d*x^n)^(-q), x], x] /; FreeQ[{a, b, c, d}, x] && NeQ[b*c - a*d, 0] && IGtQ[n, 0] && IGtQ[p, 0] && ILt
Q[q, 0] && GeQ[p, -q]

Rule 3742

Int[((a_) + (b_.)*((c_.)*tan[(e_.) + (f_.)*(x_)])^(n_))^(p_), x_Symbol] :> With[{ff = FreeFactors[Tan[e + f*x]
, x]}, Dist[c*(ff/f), Subst[Int[(a + b*(ff*x)^n)^p/(c^2 + ff^2*x^2), x], x, c*(Tan[e + f*x]/ff)], x]] /; FreeQ
[{a, b, c, e, f, n, p}, x] && (IntegersQ[n, p] || IGtQ[p, 0] || EqQ[n^2, 4] || EqQ[n^2, 16])

Rubi steps \begin{align*} \text {integral}& = \frac {\text {Subst}\left (\int \frac {\left (a+b x^2\right )^2}{1+x^2} \, dx,x,\tan (e+f x)\right )}{f} \\ & = \frac {\text {Subst}\left (\int \left ((2 a-b) b+b^2 x^2+\frac {(a-b)^2}{1+x^2}\right ) \, dx,x,\tan (e+f x)\right )}{f} \\ & = \frac {(2 a-b) b \tan (e+f x)}{f}+\frac {b^2 \tan ^3(e+f x)}{3 f}+\frac {(a-b)^2 \text {Subst}\left (\int \frac {1}{1+x^2} \, dx,x,\tan (e+f x)\right )}{f} \\ & = (a-b)^2 x+\frac {(2 a-b) b \tan (e+f x)}{f}+\frac {b^2 \tan ^3(e+f x)}{3 f} \\ \end{align*}

Mathematica [A] (verified)

Time = 0.55 (sec) , antiderivative size = 73, normalized size of antiderivative = 1.59 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=\frac {\tan (e+f x) \left (\frac {3 (a-b)^2 \text {arctanh}\left (\sqrt {-\tan ^2(e+f x)}\right )}{\sqrt {-\tan ^2(e+f x)}}+b \left (6 a-b \left (3-\tan ^2(e+f x)\right )\right )\right )}{3 f} \]

[In]

Integrate[(a + b*Tan[e + f*x]^2)^2,x]

[Out]

(Tan[e + f*x]*((3*(a - b)^2*ArcTanh[Sqrt[-Tan[e + f*x]^2]])/Sqrt[-Tan[e + f*x]^2] + b*(6*a - b*(3 - Tan[e + f*
x]^2))))/(3*f)

Maple [A] (verified)

Time = 0.03 (sec) , antiderivative size = 49, normalized size of antiderivative = 1.07

method result size
norman \(\left (a^{2}-2 a b +b^{2}\right ) x +\frac {\left (2 a -b \right ) b \tan \left (f x +e \right )}{f}+\frac {b^{2} \tan \left (f x +e \right )^{3}}{3 f}\) \(49\)
derivativedivides \(\frac {\frac {b^{2} \tan \left (f x +e \right )^{3}}{3}+2 a b \tan \left (f x +e \right )-b^{2} \tan \left (f x +e \right )+\left (a^{2}-2 a b +b^{2}\right ) \arctan \left (\tan \left (f x +e \right )\right )}{f}\) \(59\)
default \(\frac {\frac {b^{2} \tan \left (f x +e \right )^{3}}{3}+2 a b \tan \left (f x +e \right )-b^{2} \tan \left (f x +e \right )+\left (a^{2}-2 a b +b^{2}\right ) \arctan \left (\tan \left (f x +e \right )\right )}{f}\) \(59\)
parallelrisch \(\frac {b^{2} \tan \left (f x +e \right )^{3}+3 a^{2} f x -6 a b f x +3 b^{2} f x +6 a b \tan \left (f x +e \right )-3 b^{2} \tan \left (f x +e \right )}{3 f}\) \(60\)
parts \(x \,a^{2}+\frac {b^{2} \left (\frac {\tan \left (f x +e \right )^{3}}{3}-\tan \left (f x +e \right )+\arctan \left (\tan \left (f x +e \right )\right )\right )}{f}+\frac {2 a b \left (\tan \left (f x +e \right )-\arctan \left (\tan \left (f x +e \right )\right )\right )}{f}\) \(63\)
risch \(x \,a^{2}-2 x a b +x \,b^{2}-\frac {4 i b \left (-3 a \,{\mathrm e}^{4 i \left (f x +e \right )}+3 b \,{\mathrm e}^{4 i \left (f x +e \right )}-6 a \,{\mathrm e}^{2 i \left (f x +e \right )}+3 b \,{\mathrm e}^{2 i \left (f x +e \right )}-3 a +2 b \right )}{3 f \left ({\mathrm e}^{2 i \left (f x +e \right )}+1\right )^{3}}\) \(92\)

[In]

int((a+b*tan(f*x+e)^2)^2,x,method=_RETURNVERBOSE)

[Out]

(a^2-2*a*b+b^2)*x+(2*a-b)*b*tan(f*x+e)/f+1/3*b^2*tan(f*x+e)^3/f

Fricas [A] (verification not implemented)

none

Time = 0.27 (sec) , antiderivative size = 51, normalized size of antiderivative = 1.11 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=\frac {b^{2} \tan \left (f x + e\right )^{3} + 3 \, {\left (a^{2} - 2 \, a b + b^{2}\right )} f x + 3 \, {\left (2 \, a b - b^{2}\right )} \tan \left (f x + e\right )}{3 \, f} \]

[In]

integrate((a+b*tan(f*x+e)^2)^2,x, algorithm="fricas")

[Out]

1/3*(b^2*tan(f*x + e)^3 + 3*(a^2 - 2*a*b + b^2)*f*x + 3*(2*a*b - b^2)*tan(f*x + e))/f

Sympy [A] (verification not implemented)

Time = 0.11 (sec) , antiderivative size = 68, normalized size of antiderivative = 1.48 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=\begin {cases} a^{2} x - 2 a b x + \frac {2 a b \tan {\left (e + f x \right )}}{f} + b^{2} x + \frac {b^{2} \tan ^{3}{\left (e + f x \right )}}{3 f} - \frac {b^{2} \tan {\left (e + f x \right )}}{f} & \text {for}\: f \neq 0 \\x \left (a + b \tan ^{2}{\left (e \right )}\right )^{2} & \text {otherwise} \end {cases} \]

[In]

integrate((a+b*tan(f*x+e)**2)**2,x)

[Out]

Piecewise((a**2*x - 2*a*b*x + 2*a*b*tan(e + f*x)/f + b**2*x + b**2*tan(e + f*x)**3/(3*f) - b**2*tan(e + f*x)/f
, Ne(f, 0)), (x*(a + b*tan(e)**2)**2, True))

Maxima [A] (verification not implemented)

none

Time = 0.31 (sec) , antiderivative size = 58, normalized size of antiderivative = 1.26 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=a^{2} x - \frac {2 \, {\left (f x + e - \tan \left (f x + e\right )\right )} a b}{f} + \frac {{\left (\tan \left (f x + e\right )^{3} + 3 \, f x + 3 \, e - 3 \, \tan \left (f x + e\right )\right )} b^{2}}{3 \, f} \]

[In]

integrate((a+b*tan(f*x+e)^2)^2,x, algorithm="maxima")

[Out]

a^2*x - 2*(f*x + e - tan(f*x + e))*a*b/f + 1/3*(tan(f*x + e)^3 + 3*f*x + 3*e - 3*tan(f*x + e))*b^2/f

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 359 vs. \(2 (44) = 88\).

Time = 0.47 (sec) , antiderivative size = 359, normalized size of antiderivative = 7.80 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=\frac {3 \, a^{2} f x \tan \left (f x\right )^{3} \tan \left (e\right )^{3} - 6 \, a b f x \tan \left (f x\right )^{3} \tan \left (e\right )^{3} + 3 \, b^{2} f x \tan \left (f x\right )^{3} \tan \left (e\right )^{3} - 9 \, a^{2} f x \tan \left (f x\right )^{2} \tan \left (e\right )^{2} + 18 \, a b f x \tan \left (f x\right )^{2} \tan \left (e\right )^{2} - 9 \, b^{2} f x \tan \left (f x\right )^{2} \tan \left (e\right )^{2} - 6 \, a b \tan \left (f x\right )^{3} \tan \left (e\right )^{2} + 3 \, b^{2} \tan \left (f x\right )^{3} \tan \left (e\right )^{2} - 6 \, a b \tan \left (f x\right )^{2} \tan \left (e\right )^{3} + 3 \, b^{2} \tan \left (f x\right )^{2} \tan \left (e\right )^{3} + 9 \, a^{2} f x \tan \left (f x\right ) \tan \left (e\right ) - 18 \, a b f x \tan \left (f x\right ) \tan \left (e\right ) + 9 \, b^{2} f x \tan \left (f x\right ) \tan \left (e\right ) - b^{2} \tan \left (f x\right )^{3} + 12 \, a b \tan \left (f x\right )^{2} \tan \left (e\right ) - 9 \, b^{2} \tan \left (f x\right )^{2} \tan \left (e\right ) + 12 \, a b \tan \left (f x\right ) \tan \left (e\right )^{2} - 9 \, b^{2} \tan \left (f x\right ) \tan \left (e\right )^{2} - b^{2} \tan \left (e\right )^{3} - 3 \, a^{2} f x + 6 \, a b f x - 3 \, b^{2} f x - 6 \, a b \tan \left (f x\right ) + 3 \, b^{2} \tan \left (f x\right ) - 6 \, a b \tan \left (e\right ) + 3 \, b^{2} \tan \left (e\right )}{3 \, {\left (f \tan \left (f x\right )^{3} \tan \left (e\right )^{3} - 3 \, f \tan \left (f x\right )^{2} \tan \left (e\right )^{2} + 3 \, f \tan \left (f x\right ) \tan \left (e\right ) - f\right )}} \]

[In]

integrate((a+b*tan(f*x+e)^2)^2,x, algorithm="giac")

[Out]

1/3*(3*a^2*f*x*tan(f*x)^3*tan(e)^3 - 6*a*b*f*x*tan(f*x)^3*tan(e)^3 + 3*b^2*f*x*tan(f*x)^3*tan(e)^3 - 9*a^2*f*x
*tan(f*x)^2*tan(e)^2 + 18*a*b*f*x*tan(f*x)^2*tan(e)^2 - 9*b^2*f*x*tan(f*x)^2*tan(e)^2 - 6*a*b*tan(f*x)^3*tan(e
)^2 + 3*b^2*tan(f*x)^3*tan(e)^2 - 6*a*b*tan(f*x)^2*tan(e)^3 + 3*b^2*tan(f*x)^2*tan(e)^3 + 9*a^2*f*x*tan(f*x)*t
an(e) - 18*a*b*f*x*tan(f*x)*tan(e) + 9*b^2*f*x*tan(f*x)*tan(e) - b^2*tan(f*x)^3 + 12*a*b*tan(f*x)^2*tan(e) - 9
*b^2*tan(f*x)^2*tan(e) + 12*a*b*tan(f*x)*tan(e)^2 - 9*b^2*tan(f*x)*tan(e)^2 - b^2*tan(e)^3 - 3*a^2*f*x + 6*a*b
*f*x - 3*b^2*f*x - 6*a*b*tan(f*x) + 3*b^2*tan(f*x) - 6*a*b*tan(e) + 3*b^2*tan(e))/(f*tan(f*x)^3*tan(e)^3 - 3*f
*tan(f*x)^2*tan(e)^2 + 3*f*tan(f*x)*tan(e) - f)

Mupad [B] (verification not implemented)

Time = 11.85 (sec) , antiderivative size = 76, normalized size of antiderivative = 1.65 \[ \int \left (a+b \tan ^2(e+f x)\right )^2 \, dx=\frac {\mathrm {tan}\left (e+f\,x\right )\,\left (2\,a\,b-b^2\right )}{f}+\frac {\mathrm {atan}\left (\frac {\mathrm {tan}\left (e+f\,x\right )\,{\left (a-b\right )}^2}{a^2-2\,a\,b+b^2}\right )\,{\left (a-b\right )}^2}{f}+\frac {b^2\,{\mathrm {tan}\left (e+f\,x\right )}^3}{3\,f} \]

[In]

int((a + b*tan(e + f*x)^2)^2,x)

[Out]

(tan(e + f*x)*(2*a*b - b^2))/f + (atan((tan(e + f*x)*(a - b)^2)/(a^2 - 2*a*b + b^2))*(a - b)^2)/f + (b^2*tan(e
 + f*x)^3)/(3*f)